import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig(({ mode }: any) => {
	const { VITE_APP_BASE_URL } = loadEnv(mode, process.cwd());
	console.log("VITE_APP_BASE_URL", VITE_APP_BASE_URL);

	return {
		base: "./",
		plugins: [
			vue(),
			AutoImport({
				resolvers: [ElementPlusResolver()],
			}),
			Components({
				resolvers: [ElementPlusResolver()],
			}),
		],
		resolve: {
			alias: {
				"@": path.resolve(__dirname, "./src"),
			},
		},
		server: {
			host: "0.0.0.0",
			proxy: {
				"/api": {
					target: VITE_APP_BASE_URL,
					changeOrigin: false,
					rewrite: (path) => path.replace(/^\/api/, ""),
				},
			},
		},
	};
});
